package team.star.werespos.model.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

/**
 * Role class<br/>
 *
 * @author hdonghong
 * @since 2018/04/30
 */
@TableName("`role`")
@Data
@Accessors(chain = true)
public class Role implements Serializable {

    private static final long serialVersionUID = 5073991399207332891L;

    @TableId
    private Integer rid;

    private String rname;

    private String rremarks;

    @TableField(exist = false)
    private Set<Permission> permissions;

//    private Set<User> users;

    public Role() {
        permissions = new HashSet<>();
//        users = new HashSet<>();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (obj == this) {
            return true;
        }
        if (!(obj instanceof Role)) {
            return false;
        }
        Role o2 = (Role) obj;
        return (Objects.equals(this.getRid(), o2.getRid()));
    }

    @Override
    public int hashCode() {
        int hash = 17;
        hash = hash << 5 - hash + (rid == null ? 0 : rid);
        return hash;
    }
}
